package com.qf.data.service;

import com.qf.common.bean.R;
import com.qf.data.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author 千锋健哥
 */
@Service
public class CheckCodeServiceImpl implements CheckCodeService{

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public R saveCodeToRedis(String phone, String code) {
        try {
            redisUtil.setKey(phone, code, 10, TimeUnit.MINUTES);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return R.ok();
    }

    @Override
    public R getCode(String phone) {
        String value = redisUtil.getKey(phone, String.class);
        return R.ok(value);
    }

}
